export function isBulgeCCW(bulge: number) {
  return bulge > 0;
}
export function isBulgeMajorArc(bulge: number) {
  return Math.abs(bulge) > 1;
}
export function calBulgeRadius({ x: x1, y: y1 }: { x: number; y: number; }, { x: x2, y: y2 }: { x: number; y: number; }, bulge: number): number {
  const cicleAngle: number = Math.atan(bulge) * 4;
  const pointLen: number = calPointLen({ x: x1, y: y1 }, { x: x2, y: y2 });
  const radius: number = (pointLen / 2) / Math.sin(cicleAngle / 2);
  return Math.abs(radius);
}
function calPointLen({ x: x1, y: y1 }: { x: number; y: number; }, { x: x2, y: y2 }: { x: number; y: number; }): number {
  const xDiff: number = x2 - x1;
  const yDiff: number = y2 - y1;
  return Math.sqrt(xDiff * xDiff + yDiff * yDiff);
}

/** 计算线段延长线上的点 */
export function calExtendPointOnLineSegment({start, end, distance}:{start:{x:number,y:number},end:{x:number,y:number},distance:number}): {x:number,y:number} {
  const dx = end.x - start.x;
  const dy = end.y - start.y;
  const len = Math.sqrt(dx * dx + dy * dy);
  const ratio = distance / len;
  return {
    x: start.x + dx * ratio,
    y: start.y + dy * ratio
  };
}

